package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.vo.Catelog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author dingchunlin
 * @Date 2023/12/19 10:07
 * @Version 1.0.0
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;


    /**
     * 首页的跳转
     * @return
     */
    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //TODO 查询出所有的一级分类
        List<CategoryEntity> list = categoryService.getLevel1Categorys();
        model.addAttribute("categorys",list);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/catalog.json")
    public Map<String,List<Catelog2VO>> getCatelogJson(){
        Map<String,List<Catelog2VO>> map = categoryService.getCatelogJson();
        return map;
    }
}
